<?php
require_once("Includes/connection.php");
require_once("Includes/functions.php");
session_start();
if(isset($_SESSION['username'])){		
	if(isset($_POST['submit_personal_info'])){
		update_personal_info($_POST);
	}
	$query = sprintf("SELECT * FROM personal_info WHERE email='%s' ",mysql_real_escape_string($_SESSION['username']));
	$result = mysql_query($query);
	$info = mysql_fetch_assoc($result);
	$user_id = htmlentities($info["user_id"]);
	$first_name = htmlentities($info["first_name"]);
	$last_name = htmlentities($info["last_name"]);
	$email = htmlentities($info["email"]);
	$birth = htmlentities($info["birth"]);
	$gender = htmlentities($info["gender"]);
	$localization = htmlentities($info["localization"]);
	$phone = htmlentities($info["phone"]);
	$marital_status = htmlentities($info["marital_status"]);
	$type_of_work = htmlentities($info["type_of_work"]);
	$relocate = htmlentities($info["relocate"]);
	$position = htmlentities($info["position"]);
	$citizenship = htmlentities($info["citizenship"]);
	$education = htmlentities($info["education"]);
	$extracurricular = htmlentities($info["extracurricular"]);
	if(isset($_POST['submit_picture'])){
		if(upload_picture($_FILES,$user_id))
			$profile_picture = "profile_pictures/".$user_id."/profile_picture";
		else{
			if(!empty($info["profile_picture"])){
				$profile_picture = htmlentities($info["profile_picture"]);
			}
			else{
				$profile_picture = "profile_pictures/0/default.png";
			}
			$image_error="The picture you are trying to upload is more than 500Kb. Resize it and try again.";//crear otros errores
		}
	}
	else{
		if(!empty($info["profile_picture"])){
			$profile_picture = htmlentities($info["profile_picture"]);
		}
		else{
			$profile_picture = "profile_pictures/0/default.png";
		}
	}
	if(isset($_POST['submit_resume_info'])){
		$query = sprintf("SELECT * FROM resume_info WHERE user_id='%s'",$user_id);
		$result = mysql_query($query);
		if(mysql_num_rows($result) == 0){
			insert_resume_info($_POST,$user_id);
		}
		else{
			update_resume_info($_POST,$user_id);
		}
	}
	$query = sprintf("SELECT * FROM resume_info WHERE user_id='%s' ",mysql_real_escape_string($user_id));
	$result = mysql_query($query);
	$info = mysql_fetch_assoc($result);	
	$objetive = htmlentities($info["objetive"]);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="JS/functions.js"></script>
<script src="JS/scriptaculous/lib/prototype.js" type="text/javascript"></script>
<script src="JS/scriptaculous/src/scriptaculous.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="css/main.css" />
<title>Businessbook</title>
</head>
<body>
	<div id="header">
    	<table id="header_table">
        <tr>
        <td id="header_left"><a href="profile.php"><h3>BusinessBook PR</h3></a></td>
        <td id="header_center">
        <form action="profile.php" method="post">
        	<table>
            <tr>            
         	<td width="300" align="right"><input type="text" name="search" maxlength="100" size="30" value="<?php echo htmlentities($search); ?>"/></td>
            <td id="change_submit"><input type="submit" name="submit" value="Search" /></td>
            <td id="advance_search_td" width="100">
            <a href="#" onclick="Effect.BlindDown('advance_search'); change_search(0);">Advance Search</a>
            </td>
            </tr>
            </table>
        </td>
        <td id="header_right">
        	<table>
            <tr>
            <td><a href="profile.php">Profile</a></td>
            <td><a href="">Edit</a></td>
            <td><a href="index.php">Logout</a></td>
            </tr>
            </table>
        </td>            
        </tr>
        </table>
    </div>
    <table id="container_table">
    <tr><td id="container_table_left">
        <table id="left_sidebar">
        <tr>
        <td id="profile_image">
		<?php
		echo'<img src="'.$profile_picture.'" width="160"/>';		
        if(isset($_GET['ID'])){
        	echo '<div id="edit_picture"></div>';
		}
		else{
			echo '<div id="edit_picture"><span onclick="$(\'picture_form\').appear();$(\'edit_picture\').fade();$(\'picture_error\').fade();">Edit</span></div>';
		}
		if(isset($image_error))
			echo '<p id="picture_error">'.$image_error.'</p>';
		?>
        <div id="picture_form" style="display:none;">
        <form action="profile.php" method="post" enctype="multipart/form-data">
		<input style="width:160px;" type="file" name="file" id="file" />
		<input type="submit" name="submit_picture" value="Done" />
		</form>
		<p>*The size of your picture need to be 500kb or lees.</p>
        </div>
        </td></tr>
        <tr><td>
        	<div id="create_form_top"></div>
            <table id="personal_info">
            <tr>
            <td>
			<?php 
			if(isset($_GET['ID'])){
				personal_info_guest($birth,'Date of Birth','birth','Write your date of birth');
			}
			else{
				personal_info($birth,'Date of Birth','birth','Write your date of birth','text');
			}?>
            </td>
            </tr><tr>
            <td>
			<?php
			if(isset($_GET['ID'])){
				personal_info_guest($gender,'Gender','gender','(Male or Female)');
			}
			else{
				personal_info($gender,'Gender','gender','(Male or Female)','text');
			}?>
            </td>
            </tr><tr>
            <td>
			<?php
			if(isset($_GET['ID'])){
				personal_info_guest($localization,'Localization','localization','(City, State)');
			}
			else{
				personal_info($localization,'Localization','localization','(City, State)','text');
			}?>
            </td>
            </tr><tr>
            <td>
			<?php
			if(isset($_GET['ID'])){
				personal_info_guest($phone,'Phone','phone','(Home, Cel)');
			}
			else{
				personal_info($phone,'Phone','phone','(Home, Cel)','text');
			}?>
            </td>
            </tr><tr>
            <td>
			<?php
			if(isset($_GET['ID'])){
				personal_info_guest($email,'Email','email','What is your email?');
			}
			else{
				personal_info($email,'Email','email','What is your email?','text');
			}?>
            </td>
            </tr><tr>
            <td>
			<?php
			if(isset($_GET['ID'])){
				personal_info_guest($marital_status,'Marital Status','marital_status','(Single, Married, Divorsed, Widowed)');
			}
			else{
				personal_info($marital_status,'Marital Status','marital_status','(Single, Married, Divorsed, Widowed)','drop_down');
			}?>
            </td>
            </tr><tr>
            <td>
			<?php
			if(isset($_GET['ID'])){
				personal_info_guest($type_of_work,'Type of Work','type_of_work','Where do you want to work?');
			}
			else{
				personal_info($type_of_work,'Type of Work','type_of_work','Where do you want to work?','drop_down');
			}?>
            </td>
            </tr><tr>
            <td>
			<?php
			if(isset($_GET['ID'])){
				personal_info_guest($relocate,'Willing to Relocate','relocate','Are you willing to relocate?');
			}
			else{
				personal_info($relocate,'Willing to Relocate','relocate','Are you willing to relocate?','drop_down');
			}?>
            </td>
            </tr><tr>
            <td>
			<?php
			if(isset($_GET['ID'])){
				personal_info_guest($position,'Position Interested','position','What is your profesion?');
			}
			else{
				personal_info($position,'Position Interested','position','What is your profesion?','text');
			}?>
            </td>
            </tr><tr>
            <td>
			<?php
			if(isset($_GET['ID'])){
				personal_info_guest($citizenship,'American Citizenship','citizenship','Are you an American Citizen?');
			}
			else{
				personal_info($citizenship,'American Citizenship','citizenship','Are you an American Citizen?','drop_down');
			}?>
            </td>
            </tr><tr>
            <td>
			<?php
			if(isset($_GET['ID'])){
				personal_info_guest($education,'Current Education','education','Are you studing or studied?');
			}
			else{
				personal_info($education,'Current Education','education','Are you studing or studied?','drop_down');
			}?>
            </td>
            </tr><tr>
            <td>
			<?php
			if(isset($_GET['ID'])){
				personal_info_guest($extracurricular,'Extracurricular Activities','extracurricular','What do you do?');
			}
			else{
				personal_info($extracurricular,'Extracurricular Activities','extracurricular','What do you do?','text');
			}?>
            </td>
            </tr>
            </table>
            <div id="create_form_down"></div>
        </td></tr>
        </table>
    </td><td>
    <div id="advance_search" style="display:none;">
    <table>
    <tr>
    <td><input type="radio" name="advance_type" value="first_name"/> Name</td>
    <td><input type="radio" name="advance_type" value="localization" /> Localization</td>
    <td><input type="radio" name="advance_type" value="type_of_work"/> Type of Work</td></tr>
    <tr><td><input type="radio" name="advance_type" value="relocate"/> Willing to Relocate</td>
    <td><input type="radio" name="advance_type" value="education"/> Current Education</td></tr>
    <td><input type="radio" name="advance_type" value="position"/> Position interested</td>
    <td><input type="radio" name="advance_type" value="gpa"/> GPA</td></tr>   
    </table>
    <div style="text-align:right; width:596px;"><a href="#" onclick="Effect.BlindUp('advance_search');change_search(1);">Hide</a></div>
    </div>
    </form>
        <table id="content_table">
        <tr><td>
            <table id="content_top">
            <tr>
            <td id="name"><h2><?php echo $first_name.' '.$last_name;?></h2></td>
            <td id="content_top_menu"><a href="">Behavioral Info</a></td>
            <td id="content_top_menu"><a href="profile_projects.php">Projects</a></td>
            </tr>
            </table>
        </td></tr>
        <tr><td>
            <table id="content_main">
            <tr><td>
            	<?php 
				if((isset($_POST['submit']) || isset($_POST['submit_advance'])) && !empty($_POST['search'])){					
					if(isset($search_email)){
						echo'<form action="'.$_SERVER['REQUEST_URI'].'" method="post">
						<input type=hidden name=search VALUE='.$_POST['search'].'>
						<input type=hidden name=submit VALUE=search>
						<table style="width:100px; border:none;">               
						<tr>
						<td><input type="submit" name="type" value="Simple" /></td>
						<td><input type="submit" name="type" value="Detail" /></td>
						</tr>
						</table>
						</form>';
						if(!isset($_POST['type'])){
							$table_type='Detail';
						}
						else{
							$table_type=$_POST['type'];
						}
						$counter=count($search_email);
						if($table_type=='Simple'){                 
							echo '<div id="table_type_simple"> 
							<table>
							<tr>
							<th style="width:100px;">Photo</th><th style="width:95px;">Name</th><th style="width:95px;">Position</th><th style="width:90px;">Education</th><th style="width:70px;">Relocate</th><th style="width:78px;">Citezenship</th><th style="width:60px;">View</th>
							</tr>';							
							for($i=0; $i<$counter; $i++){
								echo '<tr>
								<td>';
								if(!empty($search_profile_picture[$i])){
									echo '<div><a href="profile.php?ID='.$search_id[$i].'"><img src="'.htmlentities($search_profile_picture[$i]).'" width="90"/></a></div>';
								}
								else{
									echo '<div><a href="profile.php?ID='.$search_id[$i].'"><img src="profile_pictures/0/default.png" width="90"/></a></div>';
								}
								echo '</td>
								<td>'.htmlentities($search_first_name[$i]).' '.htmlentities($search_last_name[$i]).'</td>
								<td>'.htmlentities($search_position[$i]).'</td>
								<td>'.htmlentities($search_education[$i]).'</td>
								<td>'.htmlentities($search_relocate[$i]).'</td>
								<td>'.htmlentities($search_citizenship[$i]).'</td>
								<td  style="text-decoration:underline;"><a href="profile.php?ID='.$search_id[$i].'">View</a></td>
								</tr>';
							}
							echo '</table>';
						}
						else{
							for($i=0; $i<$counter; $i++){
								echo '<div id="div_type_detail"><table id="table_type_detail">
								<tr><td>
									<table style="width:160px">
									<tr><td>';
								if(!empty($search_profile_picture[$i])){
									echo '<div><a href="profile.php?ID='.$search_id[$i].'"><img src="'.htmlentities($search_profile_picture[$i]).'" width="130"/></a></div>';
								}
								else{
									echo '<div><a href="profile.php?ID='.$search_id[$i].'"><img src="profile_pictures/0/default.png" width="130"/></a></div>';
								}
								echo '</td></tr>
									</table>
								</td><td>
									<table style="width:218px;">
									<tr><td><b>Name: </b>'.htmlentities($search_first_name[$i]).' '.htmlentities($search_last_name[$i]).'</td></tr>
									<tr><td><b>Education: </b>'.htmlentities($search_education[$i]).'</td></tr>
									<tr><td><b>Location: </b>'.htmlentities($search_localization[$i]).'</td></tr>
									<tr><td><b>Citizenship: </b>'.htmlentities($search_citizenship[$i]).'</td></tr>
									<tr><td><b>Gender: </b>'.htmlentities($search_gender[$i]).'</td></tr>
									<tr><td><b>Marital Status: </b>'.htmlentities($search_marital_status[$i]).'</td></tr>
									<tr><td><b>Type of Work: </b>'.htmlentities($search_type_of_work[$i]).'</td></tr>
									<tr><td><b>Date of Birth: </b>'.htmlentities($search_birth[$i]).'</td></tr>
									</table>
								</td><td style="vertical-align:top;">
									<table style="width:198px">
									<tr><td><b>Position Interests: </b></td></tr>	
									<tr><td>'.htmlentities($search_position[$i]).'</td></tr>	
									</table>
								</td></tr>
								</table>';
							}
						}
						echo '</div>';
                    }
					else{
						echo'<table style="text-align:center; margin:auto;">
						<tr>
						<td><h3>Nothing was found! Sorry.</h3></td>
						</tr>
						</table>';
					}					
				}
				else{
				?>          
			</td></tr>
            <tr><td> 
				<?php 
				if(isset($_GET['ID'])){
                   resume_info_guest($objetive,'Objetive','objetive','What is your goal?');
                }
                else{
                    resume_info($objetive,'Objetive','objetive','What is your goal?','text');
                }?>
                <table id="education">
                <tr><th>           
                <h3>Education:</h3>
                </th><td id="edit_td">
                <a href="#education" onclick="edit_education()" onmouseover="document.education.src='images/pencil2.png'" onmouseout="document.education.src='images/pencil.png'">
                <img name="education" src="images/pencil.png"/></a>
                </td></tr>
                <tr><td>
                <p>University of Puerto Rico at Mayaguez</p>
                <p>BSc. in Computer Science</p>
                <p>GPA: 4.00</p>
                </td><td>
                <p>December 2011</p>
                </td></tr>
                <tr><td>
                <p>MechTech Institute</p>
                <p>Certification in hacking Noobs (Advance Level)</p>
                </td><td>
                <p>May 2010</p>
                </td></tr>
                </table>
            </td></tr>
            <tr><td>
                <table id="experience">
                <tr><th>
                <h3>Experience:</h3>
                </th><td id="edit_td">
                <a href="#experience" onclick="edit_experience()" onmouseover="document.experience.src='images/pencil2.png'" onmouseout="document.experience.src='images/pencil.png'">
                <img name="experience" src="images/pencil.png"/></a>
                </td></tr>
                <tr><td>                    
                <p>Basureros PR, INC</p>
                <p>Gerente e Basura</p>
                <p>Description 1</p>
                <p>Description 2</p>
                </td><td>
                <p>Octubre 2011 - November 2011</p>
                <p>Ponce, PR</p>
                </td></tr>
                </table>
            </td></tr>
            <tr><td>
                <table id="skills">
                <tr><th>
                <h3>Skills:</h3>
                </th><td id="edit_td">
                <a href="#skills" onclick="edit_skills()" onmouseover="document.skills.src='images/pencil2.png'" onmouseout="document.skills.src='images/pencil.png'">
                <img name="skills" src="images/pencil.png"/></a>
                </td></tr>
                <tr><td>
                <strong>Languages:</strong>
                <p>English, Spanis, French, Italian</p>
                <strong>Computer:</strong>
                <p>C++, java, Python, Perl, MySQL, Linux, macOSx, Windows(All Series), Google API, PHP</p>
                </td></tr>
                </table>
            </td></tr>
            <tr><td>
                <table id="achievments">
                <tr><th>
                <h3>Achievments:</h3>
                </th><td id="edit_td">
                <a href="#achievments" onclick="edit_achievments()" onmouseover="document.achievments.src='images/pencil2.png'" onmouseout="document.achievments.src='images/pencil.png'">
                <img name="achievments" src="images/pencil.png"/></a>
                </td></tr>
                <tr><td>
                <p>The Troll of the Year</p>
                </td><td>
                <p>January 2015</p>
                </td></tr>
                </table>
            </td></tr>
            <tr><td>
                <table id="references">
                <tr><th>
                <h3>References:</h3>
                </th><td id="edit_td">
                <a href="#references" onclick="edit_references()" onmouseover="document.references.src='images/pencil2.png'" onmouseout="document.references.src='images/pencil.png'">
                <img name="references" src="images/pencil.png"/></a>
                </td></tr>
                <tr><td>
                <p>God: 666-666-6666</p>
                <p>Gezuz: 1800-herp-derp</p>
                </td></tr>
                </table>
            </td></tr>
            </table>
            <?php }?>
        </td></tr>
        </table>
    </td><td>
        <table id="right_sidebar">
        <tr><td id="right_sidebar_title">
        <b>Top Companies</b>
        </td></tr>
        <tr><td>
        <a href="company_profile.php"><img src="http://ceoworld.biz/ceo/wp-content/uploads/2009/05/lockheed-martin.jpg" width="160"/></a>
        </td></tr>
        <tr><td>
        <img src="http://financial-report.info/wp-content/uploads/2010/08/Pfizer.jpg" width="160"/>
        </td></tr>
        <tr><td  id="right_sidebar_title">
        <b>Ads</b>
        </td></tr>
        <tr><td>
        <img src="http://www.globalpov.com/images/ads.jpg" width="160"/>
        </td></tr>
        <tr><td>
        <img src="http://3.bp.blogspot.com/_n5XY0hXxUfU/S7rYNZ9pqrI/AAAAAAAAAd0/VP1lPBvvQ_w/s400/lagerfeld-cocacola-ad-500x363.jpg" width="160"/>
        </td></tr>
        </table>
    </td></tr>
    </table>
</body>
</html>
<?php 
}
else{
	header('Location: index.php');
}
?>